//
//  SMBannerView.swift
//  SomePasti
//
//  Created by 李永彬 on 2025/10/13.
//

import SwiftUI

// MARK: - 支持背景图片的 Banner 模型
struct SMBanner: Identifiable, Hashable {
    let id: Int
    let title: String
    let subtitle: String
    let backgroundColor: Color?
    let backgroundImageName: String?
    
    init(id: Int, title: String, subtitle: String, backgroundColor: Color? = nil, backgroundImageName: String? = nil) {
        self.id = id
        self.title = title
        self.subtitle = subtitle
        self.backgroundColor = backgroundColor
        self.backgroundImageName = backgroundImageName
    }
}

// MARK: - Banner 视图组件
struct SMBannerView: View {
    let banner: SMBanner
    
    var body: some View {
        ZStack {
            // 背景图片或颜色
            if let imageName = banner.backgroundImageName {
                // 使用背景图片
                Image(imageName)
                    .resizable()
                    .scaledToFit()
                    .frame(maxWidth: .infinity)
                    .cornerRadius(14)
                    .clipped()
            } else if let color = banner.backgroundColor {
                // 使用背景颜色
                color
            } else {
                // 默认背景
                LinearGradient(
                    colors: [.blue, .purple],
                    startPoint: .topLeading,
                    endPoint: .bottomTrailing
                )
            }
            
            // 内容
            VStack(spacing: 12) {
                Text(banner.title)
                    .font(.title2)
                    .fontWeight(.bold)
                    .foregroundColor(.white)
                    .shadow(radius: 2)
                
                Text(banner.subtitle)
                    .font(.body)
                    .foregroundColor(.white.opacity(0.9))
                    .shadow(radius: 1)
            }
            .padding()
            .frame(maxWidth: .infinity, maxHeight: .infinity)
        }
//        .background(Color.green)
//        .shadow(radius: 5)
    }
}

